﻿﻿﻿﻿<%@ page import="java.util.List" %>

<%@ page import="studentinformationmanagementsystem.entity.ClassSchedule" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">

<%
	List<ClassSchedule>classSchedules=(List<ClassSchedule>)request.getAttribute("classSchedules");
%>

    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
        <title>课程表管理</title>
		
		<!-- Favicon -->
        <link rel="shortcut icon" href="assets/img/favicon.png">
	
		<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,500;0,600;0,700;1,400&display=swap">
		
		<!-- Bootstrap CSS -->
        <link rel="stylesheet" href="assets/plugins/bootstrap/css/bootstrap.min.css">
		
		<!-- Fontawesome CSS -->
		<link rel="stylesheet" href="assets/plugins/fontawesome/css/fontawesome.min.css">
		<link rel="stylesheet" href="assets/plugins/fontawesome/css/all.min.css">

		<!-- Datatables CSS -->
		<link rel="stylesheet" href="assets/plugins/datatables/datatables.min.css">
		
		<!-- Main CSS -->
        <link rel="stylesheet" href="assets/css/style.css">
    </head>
    <body>
		
		<!-- Main Wrapper -->
        <div class="main-wrapper">

			<!-- Header -->
			<!--页面头部 -->
			<div class="header">

				<!-- Logo -->
				<div class="header-left">
					<a href="index.html" class="logo">
						<img src="assets/img/logo.png" alt="Logo">
					</a>
					<a href="index.html" class="logo logo-small">
						<img src="assets/img/logo-small.png" alt="Logo" width="30" height="30">
					</a>
				</div>
				<!-- /Logo -->

				<a href="javascript:void(0);" id="toggle_btn">
					<i class="fas fa-align-left"></i>
				</a>
			</div>
			<!-- /Header -->

			<!-- Sidebar -->
			<div class="sidebar" id="sidebar">
				<div class="sidebar-inner slimscroll">
					<div id="sidebar-menu" class="sidebar-menu">
						<ul>
							<li class="menu-title">
								<span>主菜单</span>
							</li>
							<li >
								<a href="index.html"><i class="fas fa-th-large"></i> <span>首页</span></a>
							</li>
							<li class="submenu">
								<a href="#"><i class="fas fa-user-graduate"></i> <span> 学生管理</span> <span class="menu-arrow"></span></a>
								<ul>
									<li><a href="students.jsp">查看所有学生</a></li>
<%--									<li><a href="student-details.html">查看学生详情</a></li>--%>
<%--									<li><a href="add-student.html">添加学生信息</a></li>--%>
<%--									<li><a href="edit-student.jsp">修改学生信息</a></li>--%>
								</ul>
							</li>
							<li>
								<a href="#"><i class="fas fa-chalkboard-teacher"></i> <span> 教师管理</span> <span class="menu-arrow"></span></a>
								<ul>
									<li><a href="teachers.jsp" >查看所有教师</a></li>
<%--									<li><a href="teacher-details.html">查看教师详情</a></li>--%>
<%--									<li><a href="add-teacher.html" class="active">添加教师信息</a></li>--%>
<%--									<li><a href="edit-teacher.html">修改教师信息</a></li>--%>
								</ul>
							</li>
<%--							<li class="submenu">--%>
<%--								<a href="#"><i class="fas fa-building"></i> <span> 院系管理</span> <span class="menu-arrow"></span></a>--%>
<%--								<ul>--%>
<%--									<li><a href="departments.html">查看所有院系</a></li>--%>
<%--									<li><a href="add-department.html">添加院系信息</a></li>--%>
<%--									<li><a href="edit-department.html">修改院系信息</a></li>--%>
<%--								</ul>--%>
<%--							</li>--%>
							<li class="submenu">
								<a href="#"><i class="fas fa-book-reader"></i> <span> 课程管理</span> <span class="menu-arrow"></span></a>
								<ul>
									<li><a href="subjects.jsp">查看所有课程</a></li>
<%--									<li><a href="add-subject.html">添加课程信息</a></li>--%>
<%--									<li><a href="edit-subject.html">修改课程信息</a></li>--%>
								</ul>
							</li>
<%--							<li class="submenu">--%>
<%--								<a href="#"><i class="fas fa-user-graduate"></i> <span> 班级管理</span> <span class="menu-arrow"></span></a>--%>
<%--								<ul>--%>
<%--									<li><a href="clazz.html">查看所有班级</a></li>--%>
<%--									<li><a href="add-clazz.html">添加班级信息</a></li>--%>
<%--									<li><a href="edit-clazz.html">修改班级信息</a></li>--%>
<%--								</ul>--%>
<%--							</li>--%>
<%--							<li class="submenu">--%>
<%--								<a href="#"><i class="fas fa-building"></i> <span> 专业管理</span> <span class="menu-arrow"></span></a>--%>
<%--								<ul>--%>
<%--									<li><a href="major.html">查看所有专业</a></li>--%>
<%--									<li><a href="add-major.html">添加专业信息</a></li>--%>
<%--									<li><a href="edit-major.html">修改专业信息</a></li>--%>
<%--								</ul>--%>
<%--							</li>--%>
<%--							<li class="submenu ">--%>
<%--								<a href="#"><i class="fas fa-chalkboard-teacher"></i> <span> 选课管理</span> <span class="menu-arrow"></span></a>--%>
<%--								<ul>--%>
<%--									<li><a href="course.html" >查看所有选修课</a></li>--%>
<%--									<li><a href="add-course.html">添加选修课信息</a></li>--%>
<%--									<li><a href="edit-course.html">修改选修课信息</a></li>--%>
<%--								</ul>--%>
<%--							</li>--%>

							<li class="submenu active" >
								<a href="#"><i class="fas fa-chalkboard-teacher"></i> <span>课程表管理</span> <span class="menu-arrow"></span></a>
								<ul>
									<li><a href="quall-class-schedule.jsp" class="active">查看课程表信息</a></li>
<%--									<li><a href="add-class-schedue.html">添加课程表信息</a></li>--%>
<%--									<li><a href="edit-class-schedule.html">修改课程表信息</a></li>--%>
								</ul>
							</li>

						</ul>
					</div>
				</div>
			</div>
			<!-- /Sidebar -->
			
			<!-- Page Wrapper -->
            <div class="page-wrapper">
                <div class="content container-fluid">
				
					<!-- Page Header -->
					<div class="page-header">
						<div class="row align-items-center">
							<div class="col">
								<h3 class="page-title">课程表</h3>
								<ul class="breadcrumb">
									<li class="breadcrumb-item"><a href="index.html">首页</a></li>
									<li class="breadcrumb-item active">课程表</li>
								</ul>
							</div>
							<div class="col-auto text-right float-right ml-auto">
								<a href="#" class="btn btn-outline-primary mr-2"><i class="fas fa-download"></i> 下载</a>
								<a href="add-class-schedue.html" class="btn btn-primary"><i class="fas fa-plus"></i></a>
						</div>
						</div>
					</div>
					<!-- /Page Header -->
				
					<div class="row">
						<div class="col-sm-12">
						
							<div class="card card-table">
								<div class="card-body">
									<div class="table-responsive">
										<table id="ClassScheduleids01" class="table table-hover table-center mb-0 datatable">
											<thead>
												<tr>
													<th>课程表ID</th>
													<th>周几</th>
													<th>课程开始时间</th>
													<th>课程结束时间</th>
													<th>是否单双周</th>
													<th>课程周数</th>
													<th>上课地点</th>
													<th class="text-right">操作</th>
												</tr>
											</thead>
											<tbody id="ClassScheduleids">

											<%
												if(classSchedules==null){
													response.sendRedirect("./ClassSchedule.do?action=queryClassSchedule");
												}else{
													for (int i = 0; i <classSchedules.size(); i++) {
														ClassSchedule classSchedules01 = classSchedules.get(i);
											%>


												<tr>
													<td><%=classSchedules01.getClassScheduleId()%></td>
													<td><%=classSchedules01.getWhichDay()%></td>
													<td><%=classSchedules01.getCurriculumTime()%></td>
													<td><%=classSchedules01.getCourseEndTime()%></td>
													<td><%=classSchedules01.getSingleAndDoubleWeek()%></td>
													<td><%=classSchedules01.getTimeOfDuration()%></td>
													<td><%=classSchedules01.getPlaceOfClass()%></td>
													<td class="text-right">
														<div class="actions">
															<a  class="btn btn-sm bg-success-light mr-2" onclick="queryClassScheduleid(this)">
																<i class="fas fa-pen"></i>
															</a>
															<a  class="btn btn-sm bg-danger-light"  onclick="deleteClassSchedule(this)">
																<i class="fas fa-trash"></i>
															</a>
														</div>
													</td>
												</tr>

											<%
													}
												}
											%>

											</tbody>
										</table>
									</div>
								</div>
							</div>							
						</div>					
					</div>					
				</div>

				<!-- Footer -->

				<!-- /Footer -->
				
			</div>
			<!-- /Page Wrapper -->
			
        </div>
		<!-- /Main Wrapper -->
		
		<!-- jQuery -->
        <script src="assets/js/jquery-3.5.1.min.js"></script>
		
		<!-- Bootstrap Core JS -->
        <script src="assets/js/popper.min.js"></script>
        <script src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
		
		<!-- Slimscroll JS -->
        <script src="assets/plugins/slimscroll/jquery.slimscroll.min.js"></script>

		<!-- Datatables JS -->
		<script src="assets/plugins/datatables/datatables.min.js"></script>
		
		<!-- Custom JS -->
		<script src="assets/js/script.js"></script>
		<script src="../../js/sweetalert.min.js" type="text/javascript"></script>





	<script>




			// $('#ClassScheduleids01').DataTable( {
			// 	ajax: {
			// 		type: 'get',
			// 		url: './ClassSchedule.do?action=queryClassSchedule',
			//         dataSrc:''
			// 	},
			// 	columns: [
			// 		{ data: "classScheduleId" },
			// 		{ data: "whichDay" },
			// 		{ data: "curriculumTime" },
			// 		{ data: "courseEndTime" },
			// 		{ data: "singleAndDoubleWeek" },
			// 		{ data: "timeOfDuration" },
			// 		{ data: "placeOfClass" },
			// 	]
			// } );



		// // 查询所有用户信息
		// function queryClassSchedule() {
		// 	$.ajax({
		// 		//接收路径
		// 		url: './ClassSchedule.do',
		// 		type: 'POST',
		// 		dataType: 'text',
		// 		data: {
		// 			action:'queryClassSchedule'
		// 		},
		// 		success:function (data) {//响应成功获取响应返回的值
		// 			// console.log(data)
		// 			var parse = JSON.parse(data);
		// 			if ( parse.length!==0){
		// 				// data:服务器响应的数据
		// 				var li="";
		// 				for (var i = 0; i <parse.length ; i++) {//回填到table当中去
		// 					li +="<tr class='ClassScheduleid'>"+
		// 							"<td>"+parse[i].classScheduleId+"</td>"+
		// 							"<td>"+parse[i].whichDay+"</td>"+
		// 							"<td>"+parse[i].curriculumTime+"</td>"+
		// 							"<td>"+parse[i].courseEndTime+"</td>"+
		// 							"<td>"+parse[i].singleAndDoubleWeek+"</td>"+
		// 							"<td>"+parse[i].timeOfDuration+"</td>"+
		// 							"<td>"+parse[i].placeOfClass+"</td>"+
		// 							"<td class='text-right'>"+
		// 							     '<div class="actions">'+
		// 							       '<a href="edit-class-schedule.html" class="btn btn-sm bg-success-light mr-2">'+
		// 							         '<i class="fas fa-pen"></i>'+
		// 							        '</a>'+
		// 							       '<a href="#" class="btn btn-sm bg-danger-light" onclick="deleteClassSchedule(this)">'+
		// 							         '<i class="fas fa-trash"></i>'+
		// 							        '</a>'+
		// 							      '</div>'+
		// 							"</td>"+
		// 							"</tr>"
		// 				}
		// 				if (li===""){
		// 					swal({
		// 						title : "查询提示提示",
		// 						type : "error",
		// 						text : "未找到课程表信息",
		// 						confirmButtonText : "确定",
		// 						closeOnConfirm : false
		// 					})
		// 				}
		// 				$('#ClassScheduleids').html(li);
		// 			}else {
		// 				swal({
		// 					title : "查询提示提示",
		// 					type : "error",
		// 					text : "暂无课程表信息",
		// 					confirmButtonText : "确定",
		// 					closeOnConfirm : false
		// 				})
		// 			}
		// 		},error: function (err) {  //响应失败
		// 			swal({
		// 				title : "查询提示信息",
		// 				type : "error",
		// 				text : "查询课程表失败",
		// 				confirmButtonText : "确定",
		// 				closeOnConfirm : false
		// 			});
		//
		// 		}
		// 	});
		// }


   	//  //查询课程表信息
     // queryClassSchedule();



		function deleteClassSchedule(Classid){
			var id = $(Classid).parent().parent().parent().children('td').eq(0).text().trim();


			$.ajax({
				//接收路径
				url: './ClassSchedule.do',
				type: 'POST',
				dataType: 'text',
				data: {
					classScheduleId:id,
					action:'deleteClassSchedule'
				},
				success:function (data) {//响应成功获取响应返回的值

					if (data==0){
						swal({
							title : "课程表删除提示",
							type : "error",
							text : "此课程已经开始上课，无法进行删除",
							confirmButtonText : "确定",
							closeOnConfirm : false
						})
					} else if (data==1){
						swal({
							title : "课程表删除提示",
							type : "error",
							text : "课表删除成功",
							confirmButtonText : "确定",
							closeOnConfirm : false
						}).then(function () {
							location.href="./ClassSchedule.do?action=queryClassSchedule"
						})

					} else {

						swal({
							title : "课程表删除提示",
							type : "error",
							text : "课表删除失败",
							confirmButtonText : "确定",
							closeOnConfirm : false
						})
					}

				},error: function (err) {  //响应失败
					swal({
						title : "删除提示",
						type : "error",
						text : "课程表删除失败",
						confirmButtonText : "确定",
						closeOnConfirm : false
					});
				}
			});
		}

			function queryClassScheduleid(Classid){
				var id = $(Classid).parent().parent().parent().children('td').eq(0).text().trim();

				console.log(id);

				$.ajax({
					//接收路径
					url: './ClassSchedule.do',
					type: 'POST',
					dataType: 'text',
					data: {
						classScheduleId:id,
						action:'queryClassScheduleid'
					},
					success:function (data) {//响应成功获取响应返回的值
						if (data=="0"){
							location.href="./edit-class-schedule.html"
						}
					},error: function (err) {  //响应失败
						swal({
							title : "删除提示",
							type : "error",
							text : "课程表删除失败",
							confirmButtonText : "确定",
							closeOnConfirm : false
						});
					}
				});
			}













	</script>

    </body>
</html>